#{extends 'CRUD/layout.html' /}
#{set title:messages.get('medicineCard.edit.title') /}
<script type="text/javascript">
var date;
$(document).ready(function() {
	date = $('#object_creationDate').val();
	var datepicker = '#object_creationDate';
	$.datepicker.setDefaults($.extend({
		minDate: new Date(1900,0,1),
		maxDate: new Date(),
		yearRange: '1900:+00',
		changeMonth: true,
		changeYear: true},
		$.datepicker.regional['']));
	$(datepicker).datepicker();
	%{
		currentLanguage = play.i18n.Lang.get();
	}%
	$(datepicker).datepicker('option', $.datepicker.regional['&{currentLanguage}'.lenght == 0 ? 'en' : '&{currentLanguage}']);
	$(datepicker).datepicker('option', 'dateFormat', 'dd-mm-yy');
	$('#object_creationDate').val(date);
});
</script>
<div id="crudShow" class="${type.name}">

    <h2 id="crudShowTitle">&{'medicineCard.edit.title'}</h2>

    <div class="objectForm">
    #{form action:@save(object._key()), enctype:'multipart/form-data'}
    	#{crud.form fields:['creationDate', 'otherInfo', 'surveys', 'patient', 'medicineCardAnamneses',
    		'medicineCardAnamnesisDiseases',  'medicineCardNosologies']}
           	#{crud.custom 'surveys'}
		    	%{surveyList = controllers.Surveys.getSurveysListByMedicineCardId(object);}%
		    	<label>&{'surveys'}</label>
				#{surveysTable surveyList: surveyList/}
        	#{/crud.custom}
        	
        	#{crud.custom 'patient'}
		    	%{patientId = controllers.MedicineCards.getPatientIdByCardId(object.medicineCardId);}%
		    	<label>&{'patient'}</label>
		    	%{patient = models.Patient.find("byPatientId", patientId).first()}%
		    	<a href="@{Patients.show(patientId)}">${patient}</a>
        	#{/crud.custom}
        	
        	#{crud.custom 'medicineCardAnamneses'}
	    		<label for="medicineCardAnamneses"><a href="@{MedicineCardAnamnesiss.list()}" class="nonUnderlined">&{'objects.medicinecardanamnesiss'}</a></label>
	    		%{anamneses = models.MedicineCardAnamnesis.find("byMedicineCard", object).fetch()}%
	    		#{if anamneses != null && !anamneses.isEmpty()}
	    		<div class="list">
					#{list items:anamneses, as:'anamnesis'}
			           	<li>
			           		<span id="${anamnesis.medicineCardAnamnesisId}" class="hiddenLinks">
								@{MedicineCardAnamnesiss.show(anamnesis.medicineCardAnamnesisId)}
			        		</span>
			        		${anamnesis.description}
		        		</li>
				    #{/list}
				</div>
				#{/if}
	    		#{else}
					&{'crud.list.empty'}	    		
	    		#{/else}
        	#{/crud.custom}
        	
        	#{crud.custom 'medicineCardAnamnesisDiseases'}
	    		<label for="medicineCardAnamnesisDiseases"><a href="@{MedicineCardAnamnesisDiseases.list()}" class="nonUnderlined">&{'objects.medicinecardanamnesisdiseases'}</a></label>
	    		%{diseases = models.MedicineCardAnamnesisDisease.find("byMedicineCard", object).fetch()}%
	    		#{if diseases != null && !diseases.isEmpty()}
	    		<div class="list">
					#{list items:diseases, as:'disease'}
			           	<li>
			           		<span id="${disease.medicineCardAnamnesisDiseaseId}" class="hiddenLinks">
								@{MedicineCardAnamnesisDiseases.show(disease.medicineCardAnamnesisDiseaseId)}
			        		</span>
			        		${disease.description}
		        		</li>
				    #{/list}
				</div>
				#{/if}
	    		#{else}
					&{'crud.list.empty'}	    		
	    		#{/else}
        	#{/crud.custom}
        	
        	#{crud.custom 'medicineCardNosologies'}
	    		<label for="medicineCardNosologys"><a href="@{MedicineCardNosologys.list()}" class="nonUnderlined">&{'objects.medicinecardnosologys'}</a></label>
	    		%{nosologies = models.MedicineCardNosology.find("byMedicineCard", object).fetch()}%
	    		#{if nosologies != null && !nosologies.isEmpty()}
	    		<div class="list">
					#{list items:nosologies, as:'nosology'}
			           	<li>
			           		<span id="${nosology.medicineCardNosologyId}" class="hiddenLinks">
								@{MedicineCardNosologys.show(nosology.medicineCardNosologyId)}
			        		</span>
			        		${nosology.description}
		        		</li>
				    #{/list}
				</div>
				#{/if}
	    		#{else}
					&{'crud.list.empty'}	    		
	    		#{/else}
        	#{/crud.custom}
        #{/crud.form}


        <p class="crudButtons">
            <input type="submit" name="_save" value="&{'crud.save', type.modelName}" />
            <input type="submit" name="_saveAndContinue" value="&{'crud.saveAndContinue', type.modelName}" />
        </p>
    #{/form}
    </div>
</div>